package io.renren.modules.behavior.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.behavior.entity.UserBehaviorLogEntity;
import io.renren.modules.behavior.service.UserBehaviorLogService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 用户行为日志表
 *
 * @author xianwenchao
 * @email 1140617792@qq.com
 * @date 2021-02-13 00:05:04
 */
@RestController
@Api(value = "用户行为日志表")
@RequestMapping("behavior/userbehaviorlog")
public class UserBehaviorLogController {
    @Autowired
    private UserBehaviorLogService userBehaviorLogService;

    /**
     * 用户行为日志表列表
     */
    @GetMapping("/list")
    @RequiresPermissions("behavior:userbehaviorlog:list")
    @ApiOperation(value = "查询用户行为日志表列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userBehaviorLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 根据id查询用户行为日志表信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("behavior:userbehaviorlog:info")
    @ApiOperation(value = "根据id查询用户行为日志表信息")
    public R info(@PathVariable("id") Long id){
		UserBehaviorLogEntity userBehaviorLog = userBehaviorLogService.getById(id);

        return R.ok().put("userBehaviorLog", userBehaviorLog);
    }

    /**
     * 新增用户行为日志表记录
     */
    @PostMapping("/save")
    @RequiresPermissions("behavior:userbehaviorlog:save")
    @ApiOperation(value = "新增用户行为日志表记录")
    public R save(@RequestBody UserBehaviorLogEntity userBehaviorLog){
		userBehaviorLogService.save(userBehaviorLog);

        return R.ok();
    }

    /**
     * 根据id修改用户行为日志表记录
     */
    @PostMapping("/update")
    @RequiresPermissions("behavior:userbehaviorlog:update")
    @ApiOperation(value = "根据id修改用户行为日志表信息")
    public R update(@RequestBody UserBehaviorLogEntity userBehaviorLog){
		userBehaviorLogService.updateById(userBehaviorLog);

        return R.ok();
    }

    /**
     * 根据id删除用户行为日志表记录
     */
    @PostMapping("/delete")
    @RequiresPermissions("behavior:userbehaviorlog:delete")
    @ApiOperation(value = "根据id删除用户行为日志表记录(非逻辑删除，建议不使用)")
    public R delete(@RequestBody Long[] ids){
		userBehaviorLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
